{extend name="template/base" /}
{block name="content"}
<div class="page-container">
    <style>
        .biankuang {
            border: 1px solid #C0C0C0;
        }
        .xuanze {
            background-color: #0a6999;
        }
    </style>
    <link rel="stylesheet" href="__STATIC__/treeTable/jquery.treetable.css" />
    <link rel="stylesheet" href="__STATIC__/treeTable/jquery.treetable.theme.default.css" />
    <script src="__STATIC__/treeTable/jquery-1.9.1.min.js"></script>
    <script src="__STATIC__/treeTable/jquery.treetable.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#tab").treetable({ expandable: true });

            // $('#tab tbody tr').bind('mousedown', function () {
            //     $('.selected').not(this).removeClass('xuanze');
            //     $(this).addClass('xuanze');
            //     // $(".selected").not(this).removeClass("selected");
            //     // $(this).toggleClass("selected");
            // });

        });
    </script>
    {include file="form" /}

    <div class="cl pd-5 bg-1 bk-gray">
        <span class="l">
            <a class="btn btn-primary radius mr-5" id="sou" href="{:url('/admin/evaluation/export_to_excel',$searchCondition)}" >excel导出</a>
            <a class="btn btn-primary radius mr-5" id="xuan" style="display: none;"  href="javascript:;" onclick="xuan()">excel导出</a>
        </span>
        <span class="r pt-5 pr-5">
            共有数据 ：<strong>{$count ?? '0'}</strong> 条
        </span>
    </div>
    <?php use think\Db;?>
    <table id="tab" class="table table-border table-bordered table-hover table-bg mt-20" border="2">
        <thead>
        <tr class="text-c">
            {include file="th" /}
            <th colspan="2" width="70">操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
            {php}
                $driverRank = Db::name('driver_rank')->where('id',$vo['driver_rank_id'])->find();
                $driverRankName = '新手';
                if($driverRank){
                    $driverRankName = $driverRank['name'];
                }
            {/php}
        <tr data-tt-id="{$vo.id}" class="text-c">
            {include file="td" /}
            <td style="width: 30px">
<!--              <a title="趟数明细" href="javascript:;" onclick="layer_open('趟数明细','/admin/evaluation/trainDetails/id/{$vo.id}.html')" class="label label-secondary radius" >趟数明细</a>-->
            </td>
        </tr>
        {if !empty($vo['order_num'])}
            <tr data-tt-id="{$vo.id}-2" data-tt-parent-id="{$vo.id}" class="text-c">
                <td></td>
                <td>出发日期</td>
                <td>结束日期</td>
                <td colspan="3" style="text-align: center">线路名称</td>
                <td>订单总数</td>
                <td>好评数</td>
                <td>差评数</td>
                <td>未评价</td>
                <td>好评率</td>
                <td>是否达标</td>
                <td style="width: 30px">操作</td>
            </tr>
                {php} static $si = 5;{/php}
            {volist name="dispatchData" id="dispatch"}
                {php} $sonId = $vo['id'].'-'.$si; {/php}
                {if ($key == $vo['id'])}
                {foreach name="dispatch" item="vo5" key="k3"}
                    <tr data-tt-id="{$sonId}-{$k3}" data-tt-parent-id="{$vo.id}" class="text-c">
                        <td></td>
                        <td>
                            {if !empty($vo5['go_date'])}
                                {$vo5.go_date | date="Y-m-d",###}
                            {/if}
                        </td>
                        <td>
                            {if !empty($vo5['end_date'])}
                                {$vo5.end_date | date="Y-m-d",###}
                            {/if}
                        </td>
                        <td colspan="3" style="text-align: left;width: 30%">
                            {$vo5.title | default='线路名称为空'}
                        </td>
                        <td>{$vo5.totalOrder}</td>
                        <td>{$vo5.good}</td>
                        <td>{$vo5.bad}</td>
                        <td>{$vo5.noEvaluation}</td>
                        <td>{$vo5.feedBack}</td>
                        <td>
                            {if ($vo5['is_reach_standard'] == 1)}
                                是
                            {else /}
                                不是
                            {/if}
                        </td>
                        <td style="width: 30px">
                            <a title="订单评价详情" href="javascript:;" onclick="layer_open('订单评价详情','/admin/evaluation/orderEvaluationDetails/id/{$vo5.id}.html',{w:'80%',h:'70%'})" class="label label-secondary radius" >订单评价详情</a>
                        </td>
                    </tr>
                {/foreach}
                {/if}
                {php} $si++; {/php}
            {/volist}
            {php} $si = 5;{/php}
        {/if}
        {/volist}
        </tbody>
    </table>
    <div class="page-bootstrap">{$page ?? ''}</div>
    <script type="text/javascript" src="__LIB__/My97DatePicker/WdatePicker.js"></script>

    <script>

        //全选
        $('#checkAlls').bind("click", function () {
            $("input[name='id[]']").prop("checked",this.checked);
            var sonChecked = $("input[name='id[]']").prop('checked');
            var allChecked = this.checked
            if (sonChecked && allChecked){
                $('#xuan').css('display','inline') // 显示选择excel导出数据
                $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
            }else{
                $('#xuan').css('display','none')
                $('#sou').css('display','inline')
            }
            console.log('你点击我了')
            console.log('你是否被选中', this.checked)
            console.log('下级的选框', $("input[name='id[]']").prop('checked'))
        });

        // 单选
        $("input[name='id[]']").bind('click', function () {
            var radioData =  $("input:checked[name='id[]']");
            // 选择数据的长度
            var len = radioData.serializeArray().length;
            if (len > 0) {
                $('#xuan').css('display','inline') // 显示选择excel导出数据
                $('#sou').css('display','none') // 隐藏部分或全部excel导出数据
            } else {
                $('#xuan').css('display','none')
                $('#sou').css('display','inline')
                $('#checkAlls').prop('checked',false); // 取消选择全选按钮
            }
            // console.log('你点击了单选')
            // console.log('点击的结果为：', this.checked)
            // console.log('你选择的数据是', radioData.serializeArray())
            // console.log('你选择的数据长度是',len)
        });

        function xuan() {
            var checkData = $("input:checked[name='id[]']");
            var dataArr = checkData.serializeArray();
            dataArr.push({name: 'search',value: 'refund_order'})
            console.log('选择的数据是', checkData.length)
            console.log('选择的数据是', checkData.serializeArray())
            console.log('选择的数组是', dataArr)
            $.ajax({
                type: 'post',
                url: '/admin/evaluation/export_to_excel',
                data: dataArr,
                success: function (res) {
                    if (res.code == 5){
                        console.log('data', res);
                        location.href = res.msg; // 下载文件
                        // 删除文件
                        unclinkFile(res.msg)
                        layer.msg('导出数据成功');
                    } else {
                        layer_open('excel导出数据','/admin/pub/role/id/1')
                    }
                }
            });
        }
        var  value = 1;
        setTimeout(unclinkFile,1200000,value); // 延迟20分钟1200000
        // 15分钟后删除文件-900000
        function unclinkFile(val) {
            console.log(val)
            setTimeout(function () {
                // 删除文件
                $.ajax({
                    type: 'post',
                    url: '/admin/order/del',
                    data: {val:val},
                    success: function (data) {
                        console.log('data', data)
                        if (data.code != 5) {
                            console.log('删除失败', data.msg)
                        }
                    }
                })
            },120000,val);
        }
    </script>
    <script>
        function driverInfo(id) {
            var url = '/admin/driver/details';
            if (!id){
                layer.msg('缺少必要的参数');
            }
            $.ajax({
                type: 'get',
                url: url,
                data:{ id: id },
                success: function (data) {
                    if (data.code == 1){
                        layer.msg(data.msg)
                        return false
                    }else{
                        layer_open('详细资料','/admin/driver/details/id/'+id,{w:'1300px',h:'750px'})
                    }
                }
            })
        }
    </script>
</div>
{/block}

